package com.lebang.controller.webapi;


import com.lebang.configuration.datasource.DataSource;
import com.lebang.example.TaskClassifyExample;
import com.lebang.example.TaskTagExample;

import com.lebang.service.TaskClassifyService;
import com.lebang.service.TaskTagService;
import com.lebang.service.sys.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/webapi/newweb")
public class NewWebController {
    @Autowired
    private TaskClassifyService taskClassifyService;
    @Autowired
    private TaskTagService taskTagService;
    @Autowired
    private DictService dictService;

    @GetMapping("/task/history")
    public String history() {
        return "/tasktemplatenew/taskMy";
    }

    @GetMapping("/task/list")
    @DataSource("commonDB")
    public String taskList(Model model){
        TaskClassifyExample classifyExample= new TaskClassifyExample();
        classifyExample.createCriteria().andEnableEqualTo(1);
        TaskTagExample tagExample = new TaskTagExample();
        tagExample.createCriteria().andEnableEqualTo(1);

        model.addAttribute("classifyList",  taskClassifyService.selectByExample(classifyExample));
        model.addAttribute("tagList", taskTagService.selectByExample(tagExample));
        return "/tasktemplatenew/taskList";
    }

    @GetMapping("/task/detail")
    public String detail() {
        return "/tasktemplatenew/taskDetail";
    }

    @GetMapping("/task/commentsdetails")
    public String tasks(String taskId, String type, Model model) {
        model.addAttribute("taskId", taskId);
        model.addAttribute("type", type);
        model.addAttribute("shareUrl",dictService.selectByKeyName("share_url").getKeyvalue());
        return "/tasktemplatenew/commentsDetail";
    }

    @GetMapping("/task/taskdetails")
    public String taskdetail(String taskId, String type, Model model) {
        if(type==null){
            type="common";
        }
        model.addAttribute("taskId", taskId);
        model.addAttribute("type", type.toLowerCase());
        model.addAttribute("shareUrl",dictService.selectByKeyName("share_url").getKeyvalue());
        return "/tasktemplatenew/taskDetail";
    }

    @GetMapping("/task/share/{taskId}")
    public String share(Model model,@PathVariable String taskId){
        model.addAttribute("taskId",taskId);
        model.addAttribute("openAddr",dictService.selectByKeyName("open_app_addr").getKeyvalue());
        model.addAttribute("downloadPkg",dictService.selectByKeyName("download_pkg").getKeyvalue());
        return "/tasktemplatenew/extension";
    }

}
